﻿using Max.PH5_2008A.ShoppingCode.Domain;
using Max.PH5_2008A.ShoppingCode.IRespository;
using Max.PH5_2008A.ShoppingCode.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Max.PH5_2008A.ShoppingCode.Service
{

    public class NewProductSPUService : BaseService<NewProductSPUEntity>, INewProductSPUService
    {
        public NewProductSPUService(INewProductSPURespository respositry) : base(respositry)
        {
        }
    }
    public class NewProductSKUService : BaseService<NewProductSKUEntity>, INewProductSKUService
    {
        INewProductSKURespository _respository; //sku仓储
        INewProductSKUImageRespository _imageRespository;  //图片仓储
        INewProductSKUCommentRespository _commentRespository; //评论仓储
        INewProductSpecRespository _specRespository;  //规格仓储
        public NewProductSKUService(INewProductSKURespository respositry,
            INewProductSKUImageRespository imageRespository,
            INewProductSKUCommentRespository commentRespository,
            INewProductSpecRespository specRespository) : base(respositry)
        {
            _respository = respositry;
            _imageRespository = imageRespository;
            _commentRespository = commentRespository;
            _specRespository = specRespository;
        }


        /// <summary>
        /// 根据SKUId获取该SKU的详情信息，包括：基本信息、图片信息、评论信息、规格信息
        /// </summary>
        /// <param name="id"></param>
        public dynamic GetSKUDetailInfoById(string id)
        {
            //基本信息
            var model = _respository.Query().Where(x => id.Equals(x.Id.ToString())).FirstOrDefault();

            //图片信息
            var images = _imageRespository.Query().Where(x => id.Equals( x.SKUId.ToString())).ToList();

            //评论信息
            var comments = _commentRespository.Query().Where(x => id.Equals(x.SKUId.ToString())).ToList();

            //规格信息(包括颜色 和尺寸)
            //1)先拿颜色
            var colors = _specRespository.Query().Where(x => x.SpecType.ToLower().Equals("color")).ToList();
            //2)再拿尺寸
            var sizes = _specRespository.Query().Where(x => x.SpecType.ToLower().Equals("size")).ToList();

            return new { info = model, images, comments, colors, sizes };
        }


    }
    public class NewProductSKUImageService : BaseService<NewProductSKUImageEntity>, INewProductSKUImageService
    {
        public NewProductSKUImageService(INewProductSKUImageRespository respositry) : base(respositry)
        {
        }
    }
    public class NewProductSKUCommentService : BaseService<NewProductSKUCommentEntity>, INewProductSKUCommentService
    {
        public NewProductSKUCommentService(INewProductSKUCommentRespository respositry) : base(respositry)
        {
        }
    }
    public class NewProductSpectService : BaseService<NewProductSpecEntity>, INewProductSpectService
    {
        public NewProductSpectService(INewProductSpecRespository respositry) : base(respositry)
        {
        }
    }
}
